package com.mlc.mlcfes1;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.bukkit.event.block.BlockPlaceEvent;

import java.nio.file.Path;
import java.util.Objects;
public final class Mlcfes1 extends JavaPlugin implements @NotNull Listener {

    @Override

    public void onEnable() {
        // Plugin startup logic

        this.saveDefaultConfig();
        System.out.println("\n\n\t\t服务器活动1插件加载中\n\n");

        Bukkit.getPluginManager().registerEvents(this, this);
        Objects.requireNonNull(Bukkit.getPluginCommand("getscore")).setExecutor(new getscore(this));
        Objects.requireNonNull(Bukkit.getPluginCommand("scoretop")).setExecutor(new scoretop(this));
    }



    @Override
    public void onDisable() {
        // Plugin shutdown logic
        System.out.println("\n\n\t\t服务器活动1插件已卸载\n\n");
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent a){
        String key = "Data." + a.getPlayer().getName() + ".score";
        int score = getConfig().contains(key)?getConfig().getInt(key):0;
        System.out.println(a.getPlayer().getName() + "目前得分" + score);
        a.getPlayer().sendMessage("目前得分" + score);
    }


    @EventHandler
    public void onBlockBreak(BlockBreakEvent e)
    {
        String key = "Data." + e.getPlayer().getName() + ".score";
        int score = getConfig().contains(key)?getConfig().getInt(key):0;
        getConfig().set(key, score + 1);
//        e.getPlayer().sendMessage("目前得分" + (score + 1));
        saveConfig();
    }

    @EventHandler
    public void onBlockPlace(BlockPlaceEvent i)
    {
        String key = "Data." + i.getPlayer().getName() + ".score";
        int score = getConfig().contains(key)?getConfig().getInt(key):0;
        getConfig().set(key, score + 1);
//        i.getPlayer().sendMessage("目前得分" + (score + 1));
        saveConfig();
    }
}
